<template>
  <div>
    
    <router-link tag="div" to="/" class="header-abs" v-show="showAbs">
      <i class="iconfont icon-fanhui header-abs-back"></i>
    </router-link> 
    <div class="header-fixed" v-show="!showAbs" :style="opacityStyle">
      景点详情
      <router-link class="header-fiexd-back" to="/">
        <i class="iconfont icon-fanhui"></i>
      </router-link>
    </div>
  </div>
</template>
<script>
export default {
  name: "detailHeader",
  data() {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    };
  },
  mounted() {
    window.addEventListener("scroll", this.handleScroll);
  },
  unmounted() {
    window.removeEventListener("scroll", this.handleScroll);
  },
  methods: {
    handleScroll() {
      let top = document.documentElement.scrollTop;
      if (top > 60) {
        let opacity = top / 140; //0---1之间
        opacity > 1 ? 1 : opacity;
        this.opacityStyle = { opacity }; //==== this.opacityStyle.opacity = opacity; 前者es6写法
        this.showAbs = false;
      } else {
        this.showAbs = true;
      }
    }
  }
};
</script>
<style lang="stylus" scoped>
@import '~styles/varibles.styl';

.header-abs {
  position: absolute;
  left: 0.2rem;
  top: 0.2rem;
  width: 0.8rem;
  height: 0.8rem;
  line-height: 0.8rem;
  border-radius: 0.4rem;
  text-align: center;
  color: #fff;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.8);

  .header-abs-back {
    color: #fff;
    font-size: 0.4rem;
  }
}

.header-fixed {
  position: fixed;
  top: 0px;
  left: 0px;
  right: 0px;
  height: $headerHeight;
  line-height: $headerHeight;
  text-align: center;
  color: #fff;
  background: $bgColor;
  font-size: 0.32rem;
  z-index: 2;

  .header-fiexd-back {
    position: absolute;
    top: 0;
    left: 0;
    width: 0.64rem;
    text-align: center;
    font-size: 0.4rem;
    color: #fff;
  }
}
</style>
